#!/bin/bash
if [ ! -d /var/cache/kylin-system-updater ];then
    mkdir -p /var/cache/kylin-system-updater
fi
if [ ! -f /var/cache/kylin-system-updater/kylin-system-updater.db ];then
    echo "Copying database to the specified path ..."
    cp -r /usr/share/kylin-system-updater/kylin-system-updater.db  /var/cache/kylin-system-updater/
fi
systemctl enable kylin-system-updater.service

if [ ! -d /var/log/kylin-unattended-upgrades ];then
    mkdir -p /var/log/kylin-unattended-upgrades
fi
if [ -f /var/lib/unattended-upgrades/unattended-upgrade.conf ];then
	echo "unattended-upgrade.conf exists,removing..."
	rm /var/lib/unattended-upgrades/unattended-upgrade.conf
fi
chmod +x /usr/bin/kylin-unattended-upgrade-shutdown
chmod +x /usr/bin/kylin-unattended-upgrade
systemctl enable kylin-unattended-upgrades.service

if [ -f /usr/share/kylin-system-updater/SystemUpdater/Core/DataMigration.py ];then
    # echo "Database record migration"
    # /usr/share/kylin-system-updater/SystemUpdater/Core/DataMigration.py -m
    /usr/share/kylin-system-updater/SystemUpdater/Core/DataMigration.py -u appname_cn=
    /usr/share/kylin-system-updater/SystemUpdater/Core/DataMigration.py -t=tid_search
    /usr/share/kylin-system-updater/SystemUpdater/Core/DataMigration.py -u status_cn=
    /usr/share/kylin-system-updater/SystemUpdater/Core/DataMigration.py -u changelog=
    /usr/share/kylin-system-updater/SystemUpdater/Core/DataMigration.py -f init_version="yes"
fi
